﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FastMVVM.WPF4.Template.ViewModel;
using FastMVVM.Core;
using System.Windows.Media.Animation;

namespace FastMVVM.WPF4.Template.View
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindowView : Window, IView<MainWindowViewModel>
    {
        // The ViewModel should be the logic layer.
        // Use XAML Binding to access his properties.
        public MainWindowViewModel ViewModel { get; set; }

        // The order of the calls need to be preservated.
        // Do not add any additional code to this, unless you really know what are you doing.
        // Any other initilization logic should be at the "Window_Loaded".
        public MainWindowView()
        {
            ViewModel = ViewModelFactory.New<MainWindowViewModel>();
            // if you want to share the same ViewModel with diferent Views change to:
            //ViewModel = ViewModelFactory.GetInstance<MainWindowViewModel>();

            SetViewModelEventHandlers();
            
            InitializeComponent();
        }

        // Occurs only after all the XAML's controls have been created.
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = ViewModel;

            ViewModel.LoadMessage();
        }

        // Use to set the event handler to all the ViewModel's events.
        public void SetViewModelEventHandlers()
        {
            ViewModel.ShowMessage += ViewModel_ShowMessage;
        }

        private void ViewModel_ShowMessage(object sender, EventArgs e)
        {
            tbMessage.Visibility = Visibility.Visible;
        }
    }
}
